package com.jn.exam.paperSubmit.controller;

import com.jn.exam.JwtUtils;
import com.jn.exam.R;
import com.jn.exam.paperSubmit.entity.vo.Answer;
import com.jn.exam.paperSubmit.service.IMessageProvider;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;


/**
 * @author 江南大学1033190417
 * @date 2021/11/27 23:48
 */
@RestController
@RequestMapping("/paperSubmit")
public class SendMessageController {

    @Autowired
    private IMessageProvider messageProvider;


    @ApiOperation("提交试卷")
    @PostMapping("sendPaperQuestionAnswer")
    public R sendPaperQuestionAnswer(HttpServletRequest request, String examId, @RequestBody Answer answer) {
        String studentId = JwtUtils.getMemberIdByJwtToken(request);
        boolean b = messageProvider.sendAnswer(answer, studentId, examId);
        if (b) {
            return R.ok().message("提交成功");
        }
        return R.error().message("提交失败");
    }


}
